package com.service;

import com.mapper.ConsumerMapper;
import com.pojo.Consumer;
import com.service.iter.ILoginService;
import com.util.Res;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.Objects;

@Service
@Transactional
public class LoginServiceImpl implements ILoginService {
    @Autowired
    private ConsumerMapper consumerMapper;

    /**
     * 为空
     *
     * @param consumer 用户
     * @return {@link Res}
     */
    @Override
    public Res isNull(Consumer consumer) {
        Res res = new Res();

        System.out.println(consumer);
        Consumer aNull = consumerMapper.isNull(consumer);
        if (Objects.isNull(aNull)) {
            res.setMsg("账号/密码错误");
            res.setCode(400);
        } else {
            res.setCode(200);
            res.setData(aNull);
        }
        return res;
    }

    @Override
    public Res Add(Consumer consumer) {
        Res res = new Res();
        consumer.setConsumerCreatedAt(new Date());
        int i = consumerMapper.AddConsumer(consumer);
        if (i <= 0) {
            res.setCode(400);
            res.setMsg("注册失败");
            return res;
        } else {
            res.setCode(200);
            res.setMsg("注册成功");
        }

        return res;
    }



}
